package com.lanchetech.user.controller;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import com.lanchetech.user.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "课程管理接口", tags = "课程管理接口")
@RequestMapping("/api/course")
@RestController
public class CourseController {

    @Autowired
    CourseService courseService;

    @ApiOperation("获取专栏详情")
    @GetMapping("/getColumnsDetail")
    public ResultData<Columns> getColumnsDetail(@RequestParam("id") Long id) {
        return courseService.getColumnsDetail(id);
    }

    @ApiOperation(value = "获取专栏分页", notes = "筛选条件 title, name->teacherName, type, status")
    @PostMapping("/getColumnsPage")
    public ResultData<BasePageResp<Columns>> getColumnsPage(@RequestBody PageReq req) {
        return courseService.getColumnsPage(req);
    }

    @ApiOperation("获取所有专栏列表")
    @GetMapping("/getColumnsList")
    public ResultData<List<Columns>> getColumnsList() {
        return courseService.getColumnsList();
    }

    @ApiOperation("获取课程详情")
    @GetMapping("/getCourseDetail")
    public ResultData<CourseVO> getCourseDetail(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return courseService.getCourseDetail(user, id);
    }

    @ApiOperation(value = "获取课程分页", notes = "筛选条件 title, type->auth, status")
    @PostMapping("/getCoursePage")
    public ResultData<BasePageResp<CourseVO>> getCoursePage(@RequestBody PageReq req) {
        return courseService.getCoursePage(req);
    }

    @ApiOperation(value = "获取当前课程的上一课和下一课")
    @GetMapping("/getCoursePrevAndNext")
    public ResultData<CourseVO> getCoursePrevAndNext(@RequestParam("id") Long id) {
        return courseService.getCoursePrevAndNext(id);
    }

    @ApiOperation(value = "获取指定专栏下的所有开启的课程")
    @GetMapping("/getColumnCourseList")
    public ResultData<List<CourseVO>> getColumnCourseList(@RequestParam("columnId") Long columnId) {
        return courseService.getColumnCourseList(columnId);
    }

    @ApiOperation(value = "获取课程授权分页", notes = "")
    @PostMapping("/getColumnCourseAuthPage")
    public ResultData<BasePageResp<ColumnCourseAuthVO>> getColumnCourseAuthPage(@RequestBody PageReq req) {
        return courseService.getColumnCourseAuthPage(req);
    }

    @ApiOperation(value = "课程点赞", notes = "0 取消点赞 1 点赞")
    @GetMapping("/toggleCourseGoods")
    public BaseResp toggleCourseGoods(@RequestParam("courseId") Long courseId, @RequestParam("goods") Integer goods) {
        return courseService.toggleCourseGoods(courseId, goods);
    }

    @ApiOperation("删除自己的课程评论")
    @GetMapping("/deleteCourseComment")
    public BaseResp deleteCourseComment(@RequestParam("id") Long id) {
        return courseService.deleteCourseComment(id);
    }

    @ApiOperation("获取课程评论分页")
    @PostMapping("/getCourseCommentPage")
    public ResultData<BasePageResp<CourseCommentPageVO>> getCourseCommentPage(@RequestBody PageReq req) {
        return courseService.getCourseCommentPage(req);
    }

    @ApiOperation("发布课程评论")
    @PostMapping("/editCourseComment")
    public BaseResp editCourseComment(@RequestBody CourseComment req) {
        return courseService.editCourseComment(req);
    }

    @ApiOperation("点赞评论")
    @GetMapping("/toggleCourseGood")
    public BaseResp toggleCourseGood(@RequestParam("courseId") Long courseId, @RequestParam("commentId") Long commentId) {
        return courseService.toggleCourseCommentGood(courseId, commentId);
    }

    @ApiOperation("创建专栏或课程订阅（收藏）")
    @PostMapping("/createColumnCourseCollect")
    public BaseResp createColumnCourseCollect(@RequestBody ColumnCourseCollect req) {
        return courseService.createColumnCourseCollect(req);
    }

    @ApiOperation("删除专栏或课程订阅（收藏）")
    @PostMapping("/deleteColumnCourseCollect")
    public BaseResp deleteColumnCourseCollect(@RequestBody ColumnCourseCollect req) {
        return courseService.deleteColumnCourseCollect(req);
    }

    @ApiOperation("获取课程订阅分页")
    @PostMapping("/getColumnCourseCollectPage")
    public ResultData<BasePageResp<ColumnCourseCollectPageVO>> getColumnCourseCollectPage(@RequestBody PageReq req) {
        return courseService.getColumnCourseCollectPage(req);
    }

    @ApiOperation("获取课程作业详情")
    @GetMapping("/getCourseHomework")
    public ResultData<CourseHomeworkVO> getCourseHomework(@RequestParam("courseId") Long courseId) {
        return courseService.getCourseHomework(courseId);
    }

    @ApiOperation("编辑课程作业")
    @PostMapping("/editHomework")
    public BaseResp editHomework(@RequestBody Homework req) {
        return courseService.editHomework(req);
    }

    @ApiOperation("获取课我的作业分页")
    @PostMapping("/getHomeworkPage")
    public ResultData<BasePageResp<HomeworkVO>> getHomeworkPage(@RequestBody PageReq req) {
        return courseService.getHomeworkPage(req);
    }

    @ApiOperation("获取荣誉分页")
    @PostMapping("/getHonorPage")
    public ResultData<BasePageResp<Honor>> getHonorPage(@RequestBody PageReq req) {
        return courseService.getHonorPage(req);
    }

    @ApiOperation("获取学分分页")
    @PostMapping("/getExpFlowPage")
    public ResultData<BasePageResp<ExpFlow>> getExpFlowPage(@RequestBody PageReq req) {
        return courseService.getExpFlowPage(req);
    }
}
